<?php
/**
 * 会员视图控制器
 */
namespace app\manage\controller\member;

use app\manage\controller\Base;

use app\common\model\Member;


class Show extends Base
{

    public function index()
    {
    	$params = $this->request->get();
        // 筛选参数
        $whereFields = ['mid','page','mname','level_id','agent_id','status','type','inviter_id','seter_id','is_agent','start','end'];
        // 查询字符串
        $whereStr = parseQuery($params,$whereFields);
        // 参数数组
        $whereData = [];
        foreach($whereFields as $field):
            if(isset($params[$field]))
                $whereData[$field] = $params[$field];
        endforeach;

        // 页面信息
        $pageData = ['title'=>'会员列表'];

        $this->assign('pageData',$pageData);
        $this->assign('whereStr',$whereStr);
        $this->assign('whereData',$whereData);

        return view();
    }


    public function map(){

        $params = $this->request->only(['fid']);
        if(!isset($params['fid']))
            $params['fid']=model('option')::getOne('init_uid');
        $fid = $params['fid'];

        // 页面信息
        $pageData = ['title'=>'会员网络'];

        $this->assign('pageData',$pageData);
        $this->assign('fid',$fid);
        return view();
    }

    /**
     * 代理中心管理
     * @return [type] [description]
     */
    public function agent(){
        $params = $this->request->get();

        // 筛选参数
        $whereFields = ['mid','page'];
        $where=[];
        foreach($whereFields as $v):
            if(isset($params[$v]))
                $where[$v] = $params[$v];
        endforeach;
        // 删选参数转成字符串
        $whereStr = arrayToQueryString($where);
        $whereStr = ltrim($whereStr,'&');

        // 页码
        $page = isset($where['page'])?$where['page']:1;
        if(!$page)
            $page = 1;

        // 页面信息
        $pageData = ['title'=>'代理中心管理'];

        $this->assign('page',$page);
        $this->assign('whereStr',$whereStr);
        $this->assign('pageData',$pageData);
        return view();
    }

    /**
     * 添加会员
     */
    public function add(){


        // 页面信息
        $pageData = ['title'=>'添加会员'];

        $this->assign('pageData',$pageData);
        return view();
    }

    /**
     * 会员编辑
     * @return [type] [description]
     */
    public function edit(){
        $mid = $this->request->get('mid');

        $model = new Member;
        $memberDetail = $model -> getDetail($mid);

        // 页面信息
        $pageData = ['title'=>'会员编辑'];

        $this->assign('pageData',$pageData);
        $this->assign('memberDetail',$memberDetail);
        return view();
    }

    public  function test(){
        echo pagination(100, 20, 2, 'http://www.baidu.com/', $queryStr = 'a=1');
    }

}
